//
//  WYTPrivateCell.m
//  WuyouTang
//
//  Created by yunbao02 on 2024/8/26.
//  Copyright © 2024 cat. All rights reserved.
//

#import "WYTPrivateCell.h"

@implementation WYTPrivateCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _lineL.backgroundColor = RGB_COLOR(@"#e4e4e4", 1);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+(WYTPrivateCell *)cellWithTab:(UITableView *)table index:(NSIndexPath *)index {
    WYTPrivateCell *cell = [table dequeueReusableCellWithIdentifier:@"WYTPrivateCell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"WYTPrivateCell" owner:nil options:nil]objectAtIndex:0];
    }
    cell.backgroundColor = UIColor.whiteColor;
    cell.contentView.backgroundColor = UIColor.whiteColor;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (IBAction)clickOpenSwitch:(UIButton *)sender {
    NSString *event = minstr([_dataDic valueForKey:@"event"]);
    int oldVal = [minstr([_dataDic valueForKey:@"val"]) intValue];
    int newVal = 0;
    if (oldVal == 0) {
        newVal = 1;
    }

    NSString *postUrl = @"";
    if ([event isEqual:@"like"]) {
        postUrl = @"User.setLikeSwitch";
    }else {
        postUrl = @"User.setCollectSwitch";
    }
    NSDictionary *postDic = @{
        @"status":@(newVal),
    };
    [MBProgressHUD showMessage:@""];
    [WYNetworking postWithUrl:postUrl Dic:postDic Suc:^(int code, id info, NSString *msg) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:msg];
        if (code==0) {
            if (self.stateEvent) {
                self.stateEvent();
            }
        }
    } Fail:^(id fail) {
        
    }];
}

- (void)setDataDic:(NSDictionary *)dataDic {
    _dataDic = dataDic;
    
    _imgIV.image = [UIImage imageNamed:minstr([_dataDic valueForKey:@"icon"])];
    _nameL.text = minstr([_dataDic valueForKey:@"name"]);
    int open = [minstr([_dataDic valueForKey:@"val"]) intValue];
    _siwtchBtn.selected = open;
}

@end
